#include "charMage.h"

charMage::charMage(pole*** tab): character::character('m')
{
    character::pToBoard=tab;
    Mana=20;
    Life=4;
    firstChecked=0;

}

charMage::charMage(pole*** tab,int flag): character::character('m')
{
    character::pToBoard=tab;
    Mana=20;
    Life=4;
    firstChecked=0;
    loadGraphica("Grafika/p1.bmp","Grafika/bufor.bmp","Grafika/MageFace.bmp");

}

charMage::charMage():character::character('m')
{
    firstChecked=0;
}

charMage::~charMage()
{
    SDL_FreeSurface(buffor);
}

int charMage::SpecialPower(SDL_Event& event,SDL_Surface*screen){
    if(Mana>=2){
        if(event.type==SDL_MOUSEBUTTONDOWN){
            if(event.button.button==SDL_BUTTON_RIGHT){
                if(firstChecked==0){
                    SDL_GetMouseState(&mouseXstate,&mouseYstate);
                    xInBoarfCheckedOne= ( (int)( (mouseXstate-20)/90) );
                    yInBoarfCheckedOne= ( (int)( (mouseYstate-20)/90) );
                    boxRGBA(screen,xInBoarfCheckedOne*90+20,
                            yInBoarfCheckedOne*90+20,
                            (xInBoarfCheckedOne*90+20)+89,
                            (yInBoarfCheckedOne*90+20)+89,
                            0,0,128,100);
                    firstChecked=1;
                }
                else{

                    if(firstChecked==1){

                        SDL_GetMouseState(&mouseXstate,&mouseYstate);
                        xInBoarfCheckedTwo= ( (int)( (mouseXstate-20)/90) );
                        yInBoarfCheckedTwo= ( (int)( (mouseYstate-20)/90) );

                        if(yInBoarfCheckedTwo==yInBoarfCheckedOne && xInBoarfCheckedTwo==xInBoarfCheckedOne){
                            pToBoard[yInBoarfCheckedOne][xInBoarfCheckedOne]->rysuj(screen);
                            firstChecked=0;
                        }
                        else{
                            boxRGBA(screen,xInBoarfCheckedTwo*90+20,
                                    yInBoarfCheckedTwo*90+20,
                                    (xInBoarfCheckedTwo*90+20)+89,
                                    (yInBoarfCheckedTwo*90+20)+89,
                                    0,0,128,100);
                        firstChecked=2;

                        }
                    }
                    else{
                        SDL_GetMouseState(&mouseXstate,&mouseYstate);

                        if(yInBoarfCheckedTwo==((int)((mouseYstate-20)/90)) && xInBoarfCheckedTwo==((int)((mouseXstate-20)/90)) ){
                            pToBoard[yInBoarfCheckedTwo][xInBoarfCheckedTwo]->rysuj(screen);
                            firstChecked=1;
                            return 0;
                        }
                        if(yInBoarfCheckedOne==((int)((mouseYstate-20)/90)) && xInBoarfCheckedOne==((int)((mouseXstate-20)/90)) ){
                            pToBoard[yInBoarfCheckedOne][xInBoarfCheckedOne]->rysuj(screen);
                            firstChecked=1;
                            return 0;
                        }
                        Mana-=2;
                        pToBoard[yInBoarfCheckedTwo][xInBoarfCheckedTwo]->rysuj(screen);
                        pToBoard[yInBoarfCheckedOne][xInBoarfCheckedOne]->rysuj(screen);
                        firstChecked=0;


                        return 2;

                    }
                }
            }
        }
    }
    return 0;
}
